package com.hainatong.jcmvvmbase.mainhome.fragment.massage;

import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentRecyclerviewBinding;
import com.hainatong.jcmvvmbase.mainhome.adapter.SysMsgAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.SysMsgBean;
import com.hainatong.jcmvvmbase.mainhome.entity.SysMsgTime;
import com.hainatong.mvvmbase.base.BaseBean;
import com.hainatong.mvvmbase.base.NoViewModel;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;

import java.util.ArrayList;
import java.util.List;

public class SysMsgFragment extends MvvmLazyFragment<FragmentRecyclerviewBinding, NoViewModel>
{
    private SysMsgAdapter adapter;
    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_recyclerview;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {

    }

    @Override
    protected void initView(View view)
    {
        adapter = new SysMsgAdapter();
        viewDataBinding.refreshlayout.setRefreshHeader(new ClassicsHeader(getActivity()));
        viewDataBinding.refreshlayout.setRefreshFooter(new ClassicsFooter(getActivity()));
        viewDataBinding.recyclerview.setLayoutManager( new LinearLayoutManager(getContext()));
        viewDataBinding.recyclerview.setHasFixedSize(true);
        viewDataBinding.recyclerview.setAdapter(adapter);

        adapter.setOnItemClickListener( (adapter1, view1, position) -> {

        } );


        viewDataBinding.refreshlayout.setOnRefreshListener( refreshLayout -> {

            refreshLayout.finishRefresh( true );

        } );

        viewDataBinding.refreshlayout.setOnLoadMoreListener( refreshLayout -> {
            refreshLayout.finishLoadMore(true);
        } );

    }


    @Override
    protected void lazyLoad()
    {
        List<BaseBean> msgList = new ArrayList<>();
        SysMsgTime msgTime = new SysMsgTime();
        msgTime.setTime( "2020-01-01 12:50" );
        msgList.add(msgTime);

        SysMsgBean msg = new SysMsgBean();
        msg.setLocation("襄阳");
        msg.setName("红头文件消息一号");
        msg.setTime("2020-01-01 12:50");

        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);


        msgList.add(msgTime);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);

        msgList.add(msgTime);
        msgList.add(msg);
        msgList.add(msg);

        adapter.setList(msgList);
        adapter.notifyDataSetChanged();

    }

}
